﻿using System;
using HMEngine.HMComponents;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace HMEngine.HMInputs {
    public enum HMPressedState {
        Pressed,
        Released,
        Held,
        Idle
    }

    public abstract class HMInputDevice : IHMUpdatable, IHMInitializable, IDisposable {
        public abstract void Initialize();
        public abstract void Update(GameTime gameTime);
        public abstract void Dispose();

        protected static HMPressedState CheckPressedState(ButtonState currentState, HMPressedState lastState) {
            if (currentState == ButtonState.Pressed) {
                if (lastState == HMPressedState.Pressed || lastState == HMPressedState.Held) {
                    return HMPressedState.Held;
                }
                return HMPressedState.Pressed;
            }

            if (lastState != HMPressedState.Released && lastState != HMPressedState.Idle) {
                return HMPressedState.Released;
            }

            return HMPressedState.Idle;
        }
    }
}